/**
 * Copyright  (c) 2009-2013 XLab,  Org. 
 * All  rights  reserved. 
 */
package org.xlab.baseframework.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.classic.Validatable;
import org.hibernate.classic.ValidationFailure;
import org.xlab.baseframework.domain.enumerate.EnumParameterType;
import org.xlab.baseframework.system.Declare;

/**
 * 系统参数实体类
 * 
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0 Sep 8, 2010
 * @since 1.0.0
 * 
 */
@Entity
@Table(name = "T_SYS_MSTR_PARAM")
public class SystemParameter extends AbstractNormalVersionControlDomainObject
		implements Validatable, Comparable<SystemParameter> {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 5962883799972542690L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = Declare.DEFAULT_SYSTEM_DB_SEQUENCE)
	@SequenceGenerator(name = Declare.DEFAULT_SYSTEM_DB_SEQUENCE, sequenceName = Declare.DEFAULT_SYSTEM_DB_SEQUENCE, allocationSize = 1, initialValue = 0)
	@Column(name = "ID_")
	private Long id;
	@Enumerated(value = EnumType.ORDINAL)
	@Column(name = "TYPE_", nullable = false, length = 20)
	private EnumParameterType type;
	@Column(name = "CODE_", nullable = false, unique = true, length = 200)
	private String code;
	@Column(name = "DESCRIPTION_", length = 2000)
	private String description;
	@Column(name = "REMARK_", length = 200)
	private String remark;
	@Column(name = "VALUE_", nullable = false, length = 400)
	private String value;
	@Column(name = "CREATED_BY_NAME", length = 200)
	private String createdByName;
	@Column(name = "LASTUPDATED_BY_NAME", length = 200)
	private String lastUpdatedByName;

	/**
	 * 默认构造函数
	 */
	public SystemParameter() {
		super();
	}

	/**
	 * 完整构造函数
	 * 
	 * @param type
	 *            参数类型
	 * @param code
	 *            参数代码
	 * @param value
	 *            参数值
	 * @param description
	 *            参数描述
	 * @param remark
	 *            参数值备注
	 * @param createdBy
	 *            创建人标识
	 * @param createdByName
	 *            创建人姓名
	 */
	public SystemParameter(EnumParameterType type, String code, String value,
			String description, String remark, String createdBy,
			String createdByName) {
		super();
		this.type = type;
		this.code = code;
		this.description = description;
		this.remark = remark;
		this.value = value;
		super.createdBy = createdBy;
		this.createdByName = createdByName;
	}

	/**
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	public int compareTo(SystemParameter o) {
		if (this.getCode().hashCode() > o.getCode().hashCode())
			return 1;
		else if (this.getCode().hashCode() < o.getCode().hashCode())
			return -1;
		else
			return 0;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @return the createdByName
	 */
	public String getCreatedByName() {
		return createdByName;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the lastUpdatedByName
	 */
	public String getLastUpdatedByName() {
		return lastUpdatedByName;
	}

	/**
	 * @return the remark
	 */
	public String getRemark() {
		return remark;
	}

	/**
	 * @return the type
	 */
	public EnumParameterType getType() {
		return type;
	}

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	/**
	 * @param code
	 *            the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @param createdByName
	 *            the createdByName to set
	 */
	public void setCreatedByName(String createdByName) {
		this.createdByName = createdByName;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param lastUpdatedByName
	 *            the lastUpdatedByName to set
	 */
	public void setLastUpdatedByName(String lastUpdatedByName) {
		this.lastUpdatedByName = lastUpdatedByName;
	}

	/**
	 * @param remark
	 *            the remark to set
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(EnumParameterType type) {
		this.type = type;
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return "SystemParameter [id=" + id + ", type=" + type + ", code="
				+ code + ", description=" + description + ", remark=" + remark
				+ ", value=" + value + ", createdByName=" + createdByName
				+ ", lastUpdatedByName=" + lastUpdatedByName + "]";
	}

	/**
	 * @see org.hibernate.classic.Validatable#validate()
	 */
	public void validate() throws ValidationFailure {
		if (this.code == null || this.value == null) {
			throw new ValidationFailure("Code or value is null.");
		}
	}
}
